// 引入store
import { storeBindingsBehavior } from "mobx-miniprogram-bindings";
import { userStore } from "@/store/index";
import { router, showToast } from "@/util/index";
import { index } from "@/api/index";
Page({
  behaviors: [storeBindingsBehavior],
  storeBindings: {
    store: userStore,
    fields: ["islogin", "userInfo"],
  },
  data: {
    adLoding: false,
    isAbsorbing: false,
    // showPrivacyModal: false,
    cartonMount: 0,
    adImages: [],
    acImages: [],
  },
  // onAgreePirvacy(e: WechatMiniprogram.BaseEvent) {
  //   this.setData({ showPrivacyModal: false });
  // },
  // onDisagreePrivacy() {
  //   showToast("不同意无法继续使用");
  // },
  // onPolicyClick() {
  //   router.navigateTo("/pages/privacy/index");
  // },
  naviagteAcList() {
    router.navigateTo("/pages/ad/activity/index");
  },
  naviagteBalance() {
    router.navigateTo("/pages/me/upmoney/index");
  },
  naviagteUser() {
    router.navigateTo("/pages/me/usersetting/index");
  },
  clickAd(e) {
    const ad = this.data.adImages[e.detail.index];
    router.navigateTo("/pages/ad/ad-view/index", {
      query: {
        id: ad.url,
      },
    });
  },
  login() {
    router.navigateTo("/pages/login/index");
  },
  recycle() {
    if (this.data.isAbsorbing) {
      return;
    }
    this.setData({
      isAbsorbing: true,
    });
    setTimeout(() => {
      this.setData({
        isAbsorbing: false,
      });
      router.navigateTo("/pages/recycle/up_order/index");
    }, 1500);
  },
  async onLoad(this: any) {
    userStore.initUserInfo();
		const data = await index();
    this.setData({
      cartonMount: data.cartonMount,
      acImages: data.adImages,
      adImages: data.adImages,
    });
  },
});
